package bai.demo.web;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * Created by Admin on 12/22 0022.
 */
@WebServlet("/testServlet")
public class TestServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("doGet....");
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String username=request.getParameter("username");
        String password=request.getParameter("password");

        System.out.println(username+password);

        String sql="select * from user where name=? and password=?";
        UserDao userDao=new UserDao();
        User user=userDao.get(sql,username,password);
        PrintWriter out=response.getWriter();

        if(user!=null){
            out.print("Hello: "+ username);
        }else{
            out.print("Sorry: "+username);
        }

        String method=request.getContextPath();
        String me=request.getServletPath();
        String m=request.getRequestURI();
        System.out.println("111:"+m);
        System.out.println("222:"+me);
        System.out.println("333:"+method);
    }

}
